package main

import (
	"fmt"
	tree2 "learngo/tree"
)

type myTreeNode struct {
	node *tree2.Node
}

func (myNode *myTreeNode) postOrder() {
	if myNode == nil || myNode.node == nil {
		return
	}
	left := myTreeNode{myNode.node.Left}
	left.postOrder()
	right := myTreeNode{myNode.node.Right}
	right.postOrder()
	myNode.node.Print()
}

func main() {
	// 树结构的定义
	var root tree2.Node
	root = tree2.Node{Value: 3}
	root.Left = &tree2.Node{}
	root.Right = &tree2.Node{5, nil, nil}
	root.Right.Left = new(tree2.Node)
	root.Left.Right = tree2.CreateNode(2)
	root.Right.Left.SetValue(4)
	root.Traverse()
	nodeCount := 0
	root.TraverseFunc(func(node *tree2.Node) {
		nodeCount++
	})
	fmt.Println("count:", nodeCount)
	//myRoot := myTreeNode{&root}
	//myRoot.postOrder()
	//fmt.Println()
	c := root.TraverseWithChannel()
	maxNode := 0
	for node := range c {
		if node.Value > maxNode {
			maxNode = node.Value
		}
	}
	fmt.Println("Max node value:", maxNode)
}
